package cn.kgc.service.impl;

import cn.kgc.dto.add.*;
import cn.kgc.entity.SmsMemberPrice;
import cn.kgc.entity.SmsSkuFullReduction;
import cn.kgc.entity.SmsSkuLadder;
import cn.kgc.entity.SmsSpuBounds;
import cn.kgc.mapper.SmsMemberPriceMapper;
import cn.kgc.mapper.SmsSkuFullReductionMapper;
import cn.kgc.mapper.SmsSkuLadderMapper;
import cn.kgc.mapper.SmsSpuBoundsMapper;
import cn.kgc.service.SmsSpuService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p></p>
 *
 * @author 李孟鸠
 * @Date: 2022年12月06日9:08
 */
@Service("smsSpuService")
public class SmsSpuServiceImpl  implements SmsSpuService {
    @Resource
    private SmsMemberPriceMapper smsMemberPriceMapper;
    
    @Resource
    private SmsSpuBoundsMapper smsSpuBoundsMapper;

    @Resource
    private SmsSkuLadderMapper smsSkuLadderMapper;

    @Resource
    private SmsSkuFullReductionMapper smsSkuFullReductionMapper;
    
    @Transactional
    public boolean addSmsSpu(SmsSpuAddDTO smsSpuAddDTO) {
        //1 新增会员价格
        List<SmsMemberPriceAddDTO> smsMemberPriceAddDTOList = smsSpuAddDTO.getSmsMemberPriceAddDTOList();
        SmsMemberPrice smsMemberPrice=new SmsMemberPrice();
        for (SmsMemberPriceAddDTO smsMemberPriceAddDTO : smsMemberPriceAddDTOList) {
            BeanUtils.copyProperties(smsMemberPriceAddDTO,smsMemberPrice);
            smsMemberPriceMapper.insert(smsMemberPrice);
        }
        //2 新增商品的积分
        SmsSpuBoundsAddDTO smsSpuBoundsAddDTO = smsSpuAddDTO.getSmsSpuBoundsAddDTO();
        SmsSpuBounds smsSpuBounds=new SmsSpuBounds();
        BeanUtils.copyProperties(smsSpuBoundsAddDTO,smsSpuBounds);
        smsSpuBoundsMapper.insert(smsSpuBounds);
        
        //3 折扣活动
        List<SmsSkuLadderAddDTO> smsSkuLadderAddDTOList = smsSpuAddDTO.getSmsSkuLadderAddDTOList();
        SmsSkuLadder smsSkuLadder=new SmsSkuLadder();
        for (SmsSkuLadderAddDTO smsSkuLadderAddDTO : smsSkuLadderAddDTOList) {
            BeanUtils.copyProperties(smsSkuLadderAddDTO,smsSkuLadder);
            smsSkuLadderMapper.insert(smsSkuLadder);
        }

        //4 满减
        List<SmsSkuFullReductionAddDTO> SkuFullReductionAddDTOList = smsSpuAddDTO.getSmsSkuFullReductionAddDTOList();
        SmsSkuFullReduction smsSkuFullReduction=new SmsSkuFullReduction();
        for (SmsSkuFullReductionAddDTO smsSkuFullReductionAddDTO : SkuFullReductionAddDTOList) {
            BeanUtils.copyProperties(smsSkuFullReductionAddDTO,smsSkuFullReduction);
            smsSkuFullReductionMapper.insert(smsSkuFullReduction);
        }

        return true;
    }
}
